package com.yyp.car.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.yyp.car.Iservice.INoticeService;
import com.yyp.car.model.Notice;

@Controller("noticeController")
@RequestMapping("/notice")
public class NoticeController {
	@Resource(name="noticeService")
	private INoticeService ins;
	
	@RequestMapping("/addNotice")
	public String addNotice(Notice notice){
		notice.setAuthor("管理员");
		ins.add(notice);
		return "redirect:/back/noticeManager";
	}
	@RequestMapping(value="/updateNotice",method=RequestMethod.GET)
	public ModelAndView updateNotice(int id){
		ModelAndView ma=new ModelAndView("/ajaxViews/editNotice");
		ma.addObject("notice", ins.findNotice(id));
		return ma;
	}
	@RequestMapping(value="/deleteNotice",method=RequestMethod.POST)
	public String deleteNotice(int id){
		ins.delete(id);
		return "redirect:/back/noticeManager";
	}
	@RequestMapping(value="/updateNotice",method=RequestMethod.POST)
	public String updateNoticep(Notice notice){
		notice.setAuthor("管理员");
		ins.update(notice);
		return "redirect:/back/noticeManager";
	}

}
